

// ME218_ISR.h
// 3 MAR 11

// ========== pixel_refresh =================
// 	
// 	The clock 2 interrupt runs at 31,250 hz
//	Half the interrupts are allocated to refresh the LCD matrix
//

// ============================





// These are the bits that I am borrowing
// from the six buttons to trigger the scope
													// PB5
// #define		SCOPE_ISR_LOW	PORTC &= 0xdf;			// 1101 1111
// #define		SCOPE_ISR_HIGH	PORTC |= 0x20;			// 0010	0000

#define		SCOPE_ISR_LOW
#define		SCOPE_ISR_HIGH


// #define		SCOPE_CLUT_LOW	PORTC &= 0xef;			// 1110 1111
// #define		SCOPE_CLUT_HIGH	PORTC |= 0x10;			// 0001 0000

#define		SCOPE_CLUT_LOW
#define		SCOPE_CLUT_HIGH


#define		SCOPE_MIDI_LOW	PORTC &= 0xf7;			// 1111 0111
#define		SCOPE_MIDI_HIGH	PORTC |= 0x08;			// 0000 1000

#define		SCOPE_BRIGHTNESS_LOW	PORTC &= 0xfb;	// 1111 1011
#define		SCOPE_BRIGHTNESS_HIGH	PORTC |= 0x04;	// 0000 0100

#define		SCOPE_GRAPHIC_SPRITES_LOW	PORTC &= 0xfd;		// 1111 1101
#define		SCOPE_GRAPHIC_SPRITES_HIGH	PORTC |= 0x02;		// 0000 0010

#define		SCOPE_BLINKY_LOW	PORTC &= 0xfe;		// 1111 1110
#define		SCOPE_BLINKY_HIGH	PORTC |= 0x01;		// 0000 0001



// =========================== ISR =====================================
/*
ISR(TWI_vect) {
	
}
*/



 
ISR(TIMER2_COMPA_vect) {
	int					i,temp;	
	unsigned char		j;
	int					CLUT_index; 
	int					red_temp, green_temp, blue_temp, temp_index, delay_temp;
	CLUT_FLASH_data		*temp_CT;
	CT_Sprite_Sizes		*qq;
	register int		temp_mask;
	// ALL_GRAPHIC_SPRITE_ARRAY*  TT_ALL_SPRITE;
	
	

	
	SCOPE_ISR_LOW
	

	
// =====================================================================
// ============================ MIDI ===================================
// =====================================================================
// This should be in assembly. The code runs 32k per second.
// The MIDI bit-banged serial port has highest priority
// We must shift the bits out at 31,250 hz
// Each interrupt shifts one bit out.
// Note: LSB first
	
	// we count down from 9 to 0
	if(MIDI_shift>=0) {
		
			temp=MIDI_word & 0x0001;
			if(temp)
				SCOPE_MIDI_HIGH
			else
				SCOPE_MIDI_LOW
				
		MIDI_word=MIDI_word>>1;
		MIDI_shift--;		// count from 9 to 0
	}
	 
	
// ===============================================================
// ===================== PoorMan =================================
// ===============================================================
	
// Using counters inside an interrupt handler is 
// a Poor_Man's multi-tasking

	Poor_Man++;
	
	if(Poor_Man & 0x01)		// 1/2 time
		goto LED_matrix_int_handler;
	
	
	if(Poor_Man & 0x02)		// 1/4 time
	goto brightness_int_handler;
	

	if(Poor_Man & 0x04)		// 1/8 time
		goto GraphicSprites_int_handler;
	
	
	// fall through to the CLUT_int_handler
 
	
// =============================================================
// ====================== CLUT sprites =========================
// ==============================================================

	
// CLUT_int_handler:

	SCOPE_CLUT_LOW
	
	if(blinky_red_led>blinky_speed) {
		blinky_red_led=0;

		if(blinky_red_toggle) {
			blinky_red_toggle=0;
			SCOPE_BLINKY_LOW
		}
		else {
			blinky_red_toggle=1;
			SCOPE_BLINKY_HIGH 
		}
	}

	
		blinky_red_led++;


			
		



	// A negative delay indicates the values are frozen
	if (ColorTable[live_CT].lc_delay>0) {
		
		// count down the timer
		ColorTable[live_CT].lc_delay--; 
		
	}
	
	else {
		
		// should we update the CLUT_Table entry?
		if (ColorTable[live_CT].lc_delay==0) {
			
			// how many steps in this CLUT sequence?
			// these values are constant. 
			qq=(CT_Sprite_Sizes*)SUPER_MAGIC_CLUT_VARIABLE;		// FIXME
	
			//qq=(CT_Sprite_Sizes*)locate_CLUT_data();
			
			qq+=live_CT;
			temp_index=pgm_read_word_near(&qq->the_sprite_len);


			//temp_index=CLUT_Sequence[live_CT].the_sprite_len;
			
			
			// have we reached the end of the sequence?
			if(ColorTable[live_CT].lc_index==temp_index) {
				// go back to beginning
				ColorTable[live_CT].lc_index=0;  
				
			}
			
			
			
			// vector to actual Sprite info
			temp_CT=(CLUT_FLASH_data*)pgm_read_word_near(&qq->the_sprite_array);
			// temp_CT=CLUT_Sequence[live_CT].the_sprite_array;
			
			// how far have we progressed through the array 
			temp_CT+=ColorTable[live_CT].lc_index;
			
			// reload with these new parameters
			delay_temp = pgm_read_word_near(&temp_CT->cs_delay);
			red_temp = pgm_read_word_near(&temp_CT->cs_red);
			green_temp = pgm_read_word_near(&temp_CT->cs_green);
			blue_temp = pgm_read_word_near(&temp_CT->cs_blue);
			
			ColorTable[live_CT].lc_delay=delay_temp;        
			ColorTable[live_CT].live_red_value= red_temp;
			ColorTable[live_CT].live_green_value= green_temp;
			ColorTable[live_CT].live_blue_value= blue_temp;
			
			// move to the next CLUT sprite
			ColorTable[live_CT].lc_index++;
		} // do nothing if the delay is negative
	} // end of update the clut
	
	// === this runs every pass ====
	live_CT++;
	if (live_CT==numCLUTs) {
		live_CT=0;            // take it from the top 
	}
	
	SCOPE_CLUT_HIGH

	 
	goto int_return;
	

// =====================================================================
// ======================== LED_matrix  ================================
// =====================================================================
	
	
LED_matrix_int_handler:

	// Master mode and SPI enable
	
	SPCR = 0x50;	// 0101 0000 i.e., (1 << SPE) | ( 1 << MSTR );   
	
	temp = 0x00;	// turn AuxLEDs off most of the time
	
	if (currentBrightness++>=MAX_BRIGHTNESS) {
		currentBrightness=0;
		
		temp=AuxLEDs;	// dim the AuxLEDs
		
		
		if (++currentCol>7) {
			currentCol=0;
			brightness_grid_index = 0;
		}
	}
	
	
	SPDR = temp;
	while (!(SPSR & (1<<SPIF))) { }
	
	
	SPDR = brightness_grid[brightness_grid_index++];	
	while (!(SPSR & (1<<SPIF))) { }
	
	
	
	SPDR = brightness_grid[brightness_grid_index++];
	while (!(SPSR & (1<<SPIF))) { }
	
	
	SPDR = brightness_grid[brightness_grid_index++];
	while (!(SPSR & (1<<SPIF))) { }

	
	// Turn display off:
	
	PORTD |= 0xfc;	// 1111 1100
	PORTB |= 0x11;	// 0001 0001
	
	// the CASE statement is more readable
	
	switch (currentCol) {
			
		case 0:
			PORTB &= 0xef;		// 1110 1111 Bit PB4
			break;
			
		case 1:
			PORTB &= 0xfe;		// 1111 1110 Bit PB0
			break;
			
		case 2:
			PORTD &= 0x7f;		// 0111 1111 Bit PD7
			break;
			
		case 3:
			PORTD &= 0xbf;		// 1011 1111 Bit PD6
			break;
			
		case 4:
			PORTD &= 0xdf;		// 1101 1111 Bit PD5
			break;
			
		case 5:
			PORTD &= 0xef;		// 1110 1111 Bit PD4
			break;
			
		case 6:
			PORTD &= 0xf7;		// 1111 0111 Bit PD3
			break;
			
		case 7:
			PORTD &= 0xfb;		// 1111 1011 Bit PD2
			break;
			
	}
	
	// ========== Pulse ==========
	// LE/DM1 input on STP16DP05
	// 20ns minimum
	
	PORTB |= 0x04;			// 0000 0100 Latch Pulse
	PORTB &= 0xfb;          //1111 1011 End Latch Pulse
	
	SPCR = 0;				//turn off spi 
	
	SCOPE_ISR_HIGH

						
	goto int_return;
	
	
// =====================================================================
// ======================== Graphic Sprites =========================
// =====================================================================

GraphicSprites_int_handler:
	
	SCOPE_GRAPHIC_SPRITES_LOW
	
	switch (sprite_smile) {
			
			// on the first pass, clear half off screen buffer
		case (0) :
			
			/*
				for (i=0; i<4; i++)
				{ 
					for (j=0; j<8; j++);
						OffScreenGameSlate[i][j]= 0;
				}
			 */
	
	
			sprite_smile=1;
			break;
			
			// now the second pass
		case (1) :
			/*
			for (i=4; i<8; i++)
			{ 
				for (j=0; j<8; j++);
					OffScreenGameSlate[i][j]= 0;
			}
			 */
			
			sprite_smile=50;
			break;

		
		case (50) :
			
			sprite_smile=100;
			break;
			
			
			
		case (100) :
				for (i=0; i<4; i++)
				{ 
					for (j=0; j<8; j++)
						GameSlate[i][j]=OffScreenGameSlate[i][j];
				}
			
			sprite_smile=101;
			break;
			
			
			// now the second pass
		case (101) :
			for (i=4; i<8; i++)
			{ 
				for (j=0; j<8; j++)
					GameSlate[i][j]=OffScreenGameSlate[i][j];
			}
			sprite_smile=100;
			break;
			
		
	}
	
	SCOPE_GRAPHIC_SPRITES_HIGH
	
	goto int_return;

// =====================================================================
// ======================= Brightness Tables  =========================
// =====================================================================
	
// ======= keep the display as fresh as a daisy ===============
	
brightness_int_handler:
//	register	prog_uint16_t 	b_mask_ref;
	register	int				bright_index;
//	register	int				the_red_level, the_green_level, the_blue_level;
//	register	prog_uint16_t		*addr0,*addr1;	
	int			temp_byte;
	
	
		
	SCOPE_BRIGHTNESS_LOW
	
	switch (daisy_color) {
			
		case (0) :
			
			// send all the red row through the CLUT mapper
			temp=GameSlate[daisy_y][0];
			CLUT_index = CLUT_mapper[temp];
			temp_byte=ColorTable[CLUT_index].live_red_value;
			work_byte_0 = nibble_to_mask[temp_byte];
			
			temp=GameSlate[daisy_y][1];
			CLUT_index = CLUT_mapper[temp];
			temp_byte=ColorTable[CLUT_index].live_red_value;
			work_byte_1 = nibble_to_mask[temp_byte];
			
			temp=GameSlate[daisy_y][2];
			CLUT_index = CLUT_mapper[temp];
			temp_byte=ColorTable[CLUT_index].live_red_value;
			work_byte_2 = nibble_to_mask[temp_byte];
			
			temp=GameSlate[daisy_y][3];
			CLUT_index =CLUT_mapper[temp];
			temp_byte=ColorTable[CLUT_index].live_red_value;
			work_byte_3 =nibble_to_mask[temp_byte];
			
			
			daisy_color = 1;
			
			
			break;
			
		case (1) :
			
	
			temp=GameSlate[daisy_y][4];
			CLUT_index = CLUT_mapper[temp];
			temp_byte=ColorTable[CLUT_index].live_red_value;
			work_byte_4 = nibble_to_mask[temp_byte];
	
			temp=GameSlate[daisy_y][5];
			CLUT_index = CLUT_mapper[temp];
			temp_byte=ColorTable[CLUT_index].live_red_value;
			work_byte_5 = nibble_to_mask[temp_byte];
			
			temp=GameSlate[daisy_y][6];
			CLUT_index =CLUT_mapper[temp];
			temp_byte=ColorTable[CLUT_index].live_red_value;
			work_byte_6 = nibble_to_mask[temp_byte];

			temp=GameSlate[daisy_y][7];
			CLUT_index =CLUT_mapper[temp];
			temp_byte=ColorTable[CLUT_index].live_red_value;
			work_byte_7 =nibble_to_mask[temp_byte];
			
			
			daisy_color = 2;
			

			break;
			
		case (2) :
			 
			temp_mask = 0;
			
			if(work_byte_0 & 0x8000)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x8000)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x8000)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x8000)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x8000)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x8000)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x8000)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x8000)
				temp_mask |= 0x01;
			
			work_mask_0=temp_mask;
			
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x4000)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x4000)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x4000)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x4000)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x4000)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x4000)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x4000)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x4000)
				temp_mask |= 0x01;
			
			work_mask_1=temp_mask;

			temp_mask = 0;
			
			if(work_byte_0 & 0x2000)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x2000)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x2000)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x2000)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x2000)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x2000)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x2000)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x2000)
				temp_mask |= 0x01;
			
			work_mask_2=temp_mask;

			temp_mask = 0;
			
			if(work_byte_0 & 0x1000)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x1000)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x1000)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x1000)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x1000)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x1000)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x1000)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x1000)
				temp_mask |= 0x01;
			
			work_mask_3=temp_mask;
			
			daisy_color = 3;
			break;
			
		case (3):
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x0800)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0800)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0800)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0800)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0800)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0800)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0800)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0800)
				temp_mask |= 0x01;
			
			work_mask_4=temp_mask;
		
			temp_mask = 0;
		
			if(work_byte_0 & 0x0400)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0400)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0400)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0400)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0400)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0400)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0400)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0400)
				temp_mask |= 0x01;
			
			work_mask_5=temp_mask;
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x0200)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0200)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0200)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0200)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0200)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0200)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0200)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0200)
				temp_mask |= 0x01;
			
			work_mask_6=temp_mask;
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x0100)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0100)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0100)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0100)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0100)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0100)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0100)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0100)
				temp_mask |= 0x01;
			
			work_mask_7=temp_mask;

			
			
			daisy_color = 4;
			break;
			
		case (4):
			
			temp_mask = 0;
			
			
			if(work_byte_0 & 0x0080)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0080)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0080)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0080)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0080)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0080)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0080)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0080)
				temp_mask |= 0x01;
			
			work_mask_8=temp_mask;

			temp_mask = 0;
			
			if(work_byte_0 & 0x0040)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0040)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0040)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0040)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0040)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0040)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0040)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0040)
				temp_mask |= 0x01;
			
			work_mask_9=temp_mask;
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x0020)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0020)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0020)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0020)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0020)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0020)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0020)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0020)
				temp_mask |= 0x01;
			
			
			work_mask_A=temp_mask;
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x0010)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0010)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0010)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0010)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0010)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0010)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0010)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0010)
				temp_mask |= 0x01;
			
			work_mask_B=temp_mask;
			
			
			daisy_color = 5;
			break;
			
		case (5):
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x0008)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0008)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0008)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0008)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0008)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0008)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0008)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0008)
				temp_mask |= 0x01;
	
			work_mask_C=temp_mask;
			
			temp_mask = 0;

			
			if(work_byte_0 & 0x0004)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0004)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0004)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0004)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0004)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0004)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0004)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0004)
				temp_mask |= 0x01;
	
			work_mask_D=temp_mask;
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x0002)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0002)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0002)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0002)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0002)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0002)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0002)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0002)
				temp_mask |= 0x01;
	
			work_mask_E=temp_mask;
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x0001)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0001)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0001)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0001)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0001)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0001)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0001)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0001)
				temp_mask |= 0x01;
			
			work_mask_F=temp_mask;
			
			
			daisy_color = 6;
			
			break;
			
		
		case (6) :
			
			bright_index = daisy_y*(15+1)*3;
			
	
			
			brightness_grid[bright_index] = work_mask_0;
			brightness_grid[bright_index+3] = work_mask_1;
			brightness_grid[bright_index+6] = work_mask_2;
			brightness_grid[bright_index+9] = work_mask_3;
			brightness_grid[bright_index+12] = work_mask_4;
			brightness_grid[bright_index+15] = work_mask_5;
			brightness_grid[bright_index+18] = work_mask_6;
			brightness_grid[bright_index+21] = work_mask_7;
			brightness_grid[bright_index+24] = work_mask_8;
			brightness_grid[bright_index+27] = work_mask_9;
			brightness_grid[bright_index+30] = work_mask_A;
			brightness_grid[bright_index+33] = work_mask_B;
			brightness_grid[bright_index+36] = work_mask_C;
			brightness_grid[bright_index+39] = work_mask_D;
			brightness_grid[bright_index+42] = work_mask_E;
			brightness_grid[bright_index+45] = work_mask_F;
			
			daisy_color = 7;
									 
			break;
			
			
		case (7) :
			
			// send all the green row through the CLUT mapper
			temp=GameSlate[daisy_y][0];
			CLUT_index = CLUT_mapper[temp];
			temp_byte=ColorTable[CLUT_index].live_green_value;
			work_byte_0 = nibble_to_mask[temp_byte];
			
			temp=GameSlate[daisy_y][1];
			CLUT_index = CLUT_mapper[temp];
			temp_byte=ColorTable[CLUT_index].live_green_value;
			work_byte_1 = nibble_to_mask[temp_byte];
			
			temp=GameSlate[daisy_y][2];
			CLUT_index = CLUT_mapper[temp];
			temp_byte=ColorTable[CLUT_index].live_green_value;
			work_byte_2 = nibble_to_mask[temp_byte];
			
			temp=GameSlate[daisy_y][3];
			CLUT_index = CLUT_mapper[temp];
			temp_byte=ColorTable[CLUT_index].live_green_value;
			work_byte_3 = nibble_to_mask[temp_byte];
	
			daisy_color = 8;
			
			break;
			
			
		case (8) :
			
			
			temp=GameSlate[daisy_y][4];
			CLUT_index = CLUT_mapper[temp];
			temp_byte=ColorTable[CLUT_index].live_green_value;
			work_byte_4 =nibble_to_mask[temp_byte];
			
			temp=GameSlate[daisy_y][5];
			CLUT_index =CLUT_mapper[temp];
			temp_byte=ColorTable[CLUT_index].live_green_value;
			work_byte_5 =nibble_to_mask[temp_byte];
			
			temp=GameSlate[daisy_y][6];
			CLUT_index = CLUT_mapper[temp];
			temp_byte=ColorTable[CLUT_index].live_green_value;
			work_byte_6 =nibble_to_mask[temp_byte];
			
			temp=GameSlate[daisy_y][7];
			CLUT_index =CLUT_mapper[temp];
			temp_byte=ColorTable[CLUT_index].live_green_value;
			work_byte_7 =nibble_to_mask[temp_byte];
			
			
			
			daisy_color = 9;
			break;
			
		case (9) :
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x8000)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x8000)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x8000)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x8000)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x8000)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x8000)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x8000)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x8000)
				temp_mask |= 0x01;
			
			work_mask_0=temp_mask;
			
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x4000)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x4000)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x4000)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x4000)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x4000)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x4000)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x4000)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x4000)
				temp_mask |= 0x01;
			
			work_mask_1=temp_mask;
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x2000)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x2000)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x2000)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x2000)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x2000)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x2000)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x2000)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x2000)
				temp_mask |= 0x01;
			
			work_mask_2=temp_mask;
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x1000)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x1000)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x1000)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x1000)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x1000)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x1000)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x1000)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x1000)
				temp_mask |= 0x01;
			
			work_mask_3=temp_mask;
			
			
			daisy_color = 10;
			break;
			
		case (10):
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x0800)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0800)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0800)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0800)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0800)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0800)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0800)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0800)
				temp_mask |= 0x01;
			
			work_mask_4=temp_mask;
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x0400)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0400)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0400)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0400)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0400)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0400)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0400)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0400)
				temp_mask |= 0x01;
			
			work_mask_5=temp_mask;
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x0200)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0200)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0200)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0200)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0200)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0200)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0200)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0200)
				temp_mask |= 0x01;
			
			work_mask_6=temp_mask;
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x0100)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0100)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0100)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0100)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0100)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0100)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0100)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0100)
				temp_mask |= 0x01;
			
			work_mask_7=temp_mask;
			
			
			
			daisy_color =11;
			break;
			
		case (11) :
			
			temp_mask = 0;
			
			
			if(work_byte_0 & 0x0080)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0080)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0080)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0080)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0080)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0080)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0080)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0080)
				temp_mask |= 0x01;
			
			work_mask_8=temp_mask;
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x0040)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0040)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0040)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0040)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0040)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0040)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0040)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0040)
				temp_mask |= 0x01;
			
			work_mask_9=temp_mask;
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x0020)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0020)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0020)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0020)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0020)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0020)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0020)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0020)
				temp_mask |= 0x01;
			
			
			work_mask_A=temp_mask;
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x0010)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0010)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0010)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0010)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0010)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0010)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0010)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0010)
				temp_mask |= 0x01;
			
			work_mask_B=temp_mask;
			
			
			daisy_color =12;
			
			break;
			
			
		case (12) :
			
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x0008)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0008)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0008)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0008)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0008)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0008)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0008)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0008)
				temp_mask |= 0x01;
			
			work_mask_C=temp_mask;
			
			temp_mask = 0;
			
			
			if(work_byte_0 & 0x0004)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0004)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0004)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0004)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0004)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0004)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0004)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0004)
				temp_mask |= 0x01;
			
			work_mask_D=temp_mask;
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x0002)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0002)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0002)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0002)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0002)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0002)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0002)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0002)
				temp_mask |= 0x01;
			
			work_mask_E=temp_mask;
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x0001)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0001)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0001)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0001)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0001)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0001)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0001)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0001)
				temp_mask |= 0x01;
			
			work_mask_F=temp_mask;
			
			daisy_color =13;
			
			break;
		
			
		case (13) :
			
			bright_index = daisy_y*(15+1)*3;
			
			
			brightness_grid[bright_index+1] = work_mask_0;
			brightness_grid[bright_index+4] = work_mask_1;
			brightness_grid[bright_index+7] = work_mask_2;
			brightness_grid[bright_index+10] = work_mask_3;
			brightness_grid[bright_index+13] = work_mask_4;
			brightness_grid[bright_index+16] = work_mask_5;
			brightness_grid[bright_index+19] = work_mask_6;
			brightness_grid[bright_index+22] = work_mask_7;
			brightness_grid[bright_index+25] = work_mask_8;
			brightness_grid[bright_index+28] = work_mask_9;
			brightness_grid[bright_index+31] = work_mask_A;
			brightness_grid[bright_index+34] = work_mask_B;
			brightness_grid[bright_index+37] = work_mask_C;
			brightness_grid[bright_index+40] = work_mask_D;
			brightness_grid[bright_index+43] = work_mask_E;
			brightness_grid[bright_index+46] = work_mask_F;
			
			daisy_color =14;
			
			break;
			
			
		case (14) :
			
			// send all the blue row through the CLUT mapper
			temp=GameSlate[daisy_y][0];
			CLUT_index = CLUT_mapper[temp];
			temp_byte=ColorTable[CLUT_index].live_blue_value;
			work_byte_0 = nibble_to_mask[temp_byte];
			
			temp=GameSlate[daisy_y][1];
			CLUT_index = CLUT_mapper[temp];
			temp_byte=ColorTable[CLUT_index].live_blue_value;
			work_byte_1 = nibble_to_mask[temp_byte];
			
			temp=GameSlate[daisy_y][2];
			CLUT_index = CLUT_mapper[temp];
			temp_byte=ColorTable[CLUT_index].live_blue_value;
			work_byte_2 =nibble_to_mask[temp_byte];
			
			temp=GameSlate[daisy_y][3];
			CLUT_index = CLUT_mapper[temp];
			temp_byte=ColorTable[CLUT_index].live_blue_value;
			work_byte_3 =nibble_to_mask[temp_byte];
			
			daisy_color =15;
			
			break;
			
			
		case (15) :
			
			
			temp=GameSlate[daisy_y][4];
			CLUT_index = CLUT_mapper[temp];
			temp_byte=ColorTable[CLUT_index].live_blue_value;
			work_byte_4 = nibble_to_mask[temp_byte];
			
			temp=GameSlate[daisy_y][5];
			CLUT_index =CLUT_mapper[temp];
			temp_byte=ColorTable[CLUT_index].live_blue_value;
			work_byte_5 =nibble_to_mask[temp_byte];
			
			temp=GameSlate[daisy_y][6];
			CLUT_index = CLUT_mapper[temp];
			temp_byte=ColorTable[CLUT_index].live_blue_value;
			work_byte_6 = nibble_to_mask[temp_byte];
			
			temp=GameSlate[daisy_y][7];
			CLUT_index =CLUT_mapper[temp];
			temp_byte=ColorTable[CLUT_index].live_blue_value;
			work_byte_7 =nibble_to_mask[temp_byte];
			
			
			daisy_color = 16;
			break;
			
		case (16) :
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x8000)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x8000)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x8000)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x8000)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x8000)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x8000)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x8000)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x8000)
				temp_mask |= 0x01;
			
			work_mask_0=temp_mask;
			
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x4000)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x4000)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x4000)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x4000)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x4000)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x4000)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x4000)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x4000)
				temp_mask |= 0x01;
			
			work_mask_1=temp_mask;
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x2000)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x2000)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x2000)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x2000)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x2000)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x2000)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x2000)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x2000)
				temp_mask |= 0x01;
			
			work_mask_2=temp_mask;
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x1000)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x1000)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x1000)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x1000)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x1000)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x1000)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x1000)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x1000)
				temp_mask |= 0x01;
			
			work_mask_3=temp_mask;
			
			
			daisy_color = 17;
			break;
			
		case (17):
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x0800)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0800)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0800)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0800)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0800)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0800)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0800)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0800)
				temp_mask |= 0x01;
			
			work_mask_4=temp_mask;
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x0400)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0400)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0400)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0400)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0400)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0400)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0400)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0400)
				temp_mask |= 0x01;
			
			work_mask_5=temp_mask;
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x0200)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0200)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0200)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0200)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0200)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0200)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0200)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0200)
				temp_mask |= 0x01;
			
			work_mask_6=temp_mask;
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x0100)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0100)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0100)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0100)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0100)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0100)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0100)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0100)
				temp_mask |= 0x01;
			
			work_mask_7=temp_mask;
			
			
		
			daisy_color = 18;
			break;
			
		case (18) :
			
			
			temp_mask = 0;
			
			
			if(work_byte_0 & 0x0080)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0080)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0080)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0080)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0080)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0080)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0080)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0080)
				temp_mask |= 0x01;
			
			work_mask_8=temp_mask;
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x0040)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0040)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0040)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0040)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0040)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0040)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0040)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0040)
				temp_mask |= 0x01;
			
			work_mask_9=temp_mask;
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x0020)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0020)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0020)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0020)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0020)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0020)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0020)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0020)
				temp_mask |= 0x01;
			
			
			work_mask_A=temp_mask;
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x0010)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0010)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0010)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0010)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0010)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0010)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0010)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0010)
				temp_mask |= 0x01;
			
			work_mask_B=temp_mask;
			
			
			daisy_color = 19;
			break;
			
		case (19) :
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x0008)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0008)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0008)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0008)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0008)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0008)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0008)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0008)
				temp_mask |= 0x01;
			
			work_mask_C=temp_mask;
			
			temp_mask = 0;
			
			
			if(work_byte_0 & 0x0004)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0004)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0004)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0004)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0004)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0004)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0004)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0004)
				temp_mask |= 0x01;
			
			work_mask_D=temp_mask;
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x0002)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0002)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0002)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0002)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0002)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0002)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0002)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0002)
				temp_mask |= 0x01;
			
			work_mask_E=temp_mask;
			
			temp_mask = 0;
			
			if(work_byte_0 & 0x0001)
				temp_mask |= 0x80;
			if(work_byte_1 & 0x0001)
				temp_mask |= 0x40;
			if(work_byte_2 & 0x0001)
				temp_mask |= 0x20;
			if(work_byte_3 & 0x0001)
				temp_mask |= 0x10;
			if(work_byte_4 & 0x0001)
				temp_mask |= 0x08;
			if(work_byte_5 & 0x0001)
				temp_mask |= 0x04;
			if(work_byte_6 & 0x0001)
				temp_mask |= 0x02;
			if(work_byte_7 & 0x0001)
				temp_mask |= 0x01;
			
			work_mask_F=temp_mask;
			
			daisy_color =20;

			break;
			
			
		case (20) :
			
			bright_index = daisy_y*(15+1)*3;
			
				
			
			brightness_grid[bright_index+2] = work_mask_0;
			brightness_grid[bright_index+5] = work_mask_1;
			brightness_grid[bright_index+8] = work_mask_2;
			brightness_grid[bright_index+11] = work_mask_3;
			brightness_grid[bright_index+14] = work_mask_4;
			brightness_grid[bright_index+17] = work_mask_5;
			brightness_grid[bright_index+20] = work_mask_6;
			brightness_grid[bright_index+23] = work_mask_7;
			brightness_grid[bright_index+26] = work_mask_8;
			brightness_grid[bright_index+29] = work_mask_9;
			brightness_grid[bright_index+32] = work_mask_A;
			brightness_grid[bright_index+35] = work_mask_B;
			brightness_grid[bright_index+38] = work_mask_C;
			brightness_grid[bright_index+41] = work_mask_D;
			brightness_grid[bright_index+44] = work_mask_E;
			brightness_grid[bright_index+47] = work_mask_F;
			
			daisy_color =0;
			
			daisy_y++;
			daisy_y &= 07;
			
			break;
			
			
									 
	}
									 

			
// daisy_exit:
	
	SCOPE_BRIGHTNESS_HIGH
	

	
// fall through to ISR
	
		 
int_return:
	
	SCOPE_ISR_HIGH
	
	asm("nop");			// FIXME !!!
						// It seems to want at least one instruction
						// between int_return and the end of ISR

	
} // end of ISR
	   


